<template>
  <div>
    <div class="nav">
      ITODO
    </div>
    <input
      class="my-value"
      placeholder="请输入待办事项"
      type="text"
      v-model="todoValue"
      @keyup="setTodoValue"
    />
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue";
import { UseTodo, IUseTodo } from "../../hooks";

export default defineComponent({
  name: "TodoInput",
  setup() {
    const todoValue = ref<string>("");
    const { setTodo }: IUseTodo = UseTodo();

    const setTodoValue = (e: KeyboardEvent): void => {
      if (e.keyCode === 13 && todoValue.value.trim().length) {
        //设置数据
        //  alert(todoValue.value);
        setTodo(todoValue.value);
        todoValue.value = "";
      }
    };
    return {
      todoValue,
      setTodoValue
    };
  }
});
</script>

<style>
.my-value {
  outline: none;
  border: none;
  width: 90%;
  height: 30px;
  border-bottom: 1px solid #a7a6a6;
  font-style: italic;
  color: #a7a6a6;
  font-size: 16px;
  margin: 10px 15px;
  margin-top: 80px;
  background: #fafafa;
}

.nav {
  position: fixed;
  top: 0;
  z-index: 10000;
  height: 50px;
  margin: 0;
  padding: 0;
  left: 0;
  right: 0;
  background: #4fd1f1d0;
  color: #fff;
  font-weight: 700;
  text-align: center;
  line-height: 50px;
  box-shadow: 0 13px 27px -5px hsla(240, 30.1%, 28%, 0.25),
    0 8px 16px -8px hsla(0, 0%, 0%, 0.3), 0 -6px 16px -6px hsla(0, 0%, 0%, 0.03);
}

</style>